package com.dingreading.cloud.ssxcx.controller;

import com.dingreading.cloud.common.base.R;
import com.dingreading.cloud.ssxcx.service.XcxStudentLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/xcx/studentLogin")
@Api(tags = "小程序-学生登陆")
public class XcxStudentLoginController {
    @Resource
    private XcxStudentLoginService xcxStudentLoginService;

    @ApiOperation(value = "获取图片验证码")
    @GetMapping(value = "/getPicCode", produces = "application/json; charset=UTF-8")
    public void getPicCode(
            HttpServletResponse response,
            @ApiParam(value = "时间戳") @RequestParam(value = "timestamp") String timestamp
    ) throws Exception {
        xcxStudentLoginService.getPicCode(response, timestamp);
    }

    @ApiOperation(value = "获取学生信息")
    @PostMapping(value = "/getStaffInfo", produces = "application/json; charset=UTF-8")
    public R<Object> getStudentInfo(HttpServletRequest request) {
        R<Object> ret = xcxStudentLoginService.getStudentInfo(request);
        return ret;
    }

    @ApiOperation(value = "学生登录")
    @PostMapping(value = "/login", produces = "application/json; charset=UTF-8")
    public R<Object> studentLogin(
            HttpServletRequest request,
            @ApiParam(value = "学生uid") @RequestParam(value = "uid") String uid,
            @ApiParam(value = "密码") @RequestParam(value = "password") String password,
            @ApiParam(value = "时间戳") @RequestParam(value = "timestamp") String timestamp,
            @ApiParam(value = "验证码") @RequestParam(value = "code") String code
    ) throws Exception {
       R<Object> ret = xcxStudentLoginService.studentLogin(request, uid, password, timestamp, code);
       return ret;
    }

    @ApiOperation(value = "修改密码")
    @PostMapping(value = "/mdyPassword", produces = "application/json; charset=UTF-8")
    public R<Object> mdyPassword(
            @ApiParam(value = "伙伴uid") @RequestParam(value = "agencyUid") String agencyUid,
            @ApiParam(value = "学生uid") @RequestParam(value = "uid") String uid,
            @ApiParam(value = "新密码") @RequestParam(value = "newPass") String newPass,
            @ApiParam(value = "确认新密码") @RequestParam(value = "confirmPass") String confirmPass
    ) {
        R<Object> ret = xcxStudentLoginService.mdyPassword(agencyUid, uid, newPass, confirmPass);
        return ret;
    }

    @ApiOperation(value = "退出登录")
    @PostMapping(value = "/logout", produces = "application/json; charset=UTF-8")
    public R<Object> logout(
            @ApiParam(value = "伙伴uid") @RequestParam(value = "agencyUid") String agencyUid,
            @ApiParam(value = "学生uid") @RequestParam(value = "uid") String uid
    ) {
        R<Object> ret = xcxStudentLoginService.logout(agencyUid, uid);
        return ret;
    }

}
